// pages/my/addressAdmin/addressAdmin.js
const App = getApp();
const utils = require('../../../utils/util.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page:0,
    list:[],
    hasMoreData:true,
    noContent:false,
    type:'',//判断页面来源
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      type:options.type
    })
  },
  getAddressList:function () {
    let page = this.data.page;
    let that = this;
    utils.requestUrl({
      url:'/niu/apiv3/fahuo_address_getlist.php',
      params:{
        markid:wx.getStorageSync('markId'),
        Page:page
      }
    }).then((res) =>{
      // let data = res.data
      console.log(res.data)
      var contentListTem = that.data.list;
        if (res.data.datacount == 0 || res.data.datacount == null) {
          this.setData({
            noContent:true
          })
        }else{
          this.setData({
            noContent:false
          })
        }
        if (res.data.datacount > 0) {
          var contentList = res.data.data
          

          if (contentList.length < res.data.pagesize) {
            this.setData({
              list:contentListTem.concat(contentList),
              hasMoreData: false
            })
          }else{
            this.setData({
              list: contentListTem.concat(contentList),
              hasMoreData: true,
              page: page + 1
            })
          }
        }
    })
  },
  goToDetail: function(e){
    let id = e.currentTarget.dataset.id;
    let name = e.currentTarget.dataset.name;
    let phone = e.currentTarget.dataset.phone;
    let local1 = e.currentTarget.dataset.local1;
    let local2 = e.currentTarget.dataset.local2;
    let local3 = e.currentTarget.dataset.local3;
    let adress = e.currentTarget.dataset.adress;
    let local1name = e.currentTarget.dataset.local1name;
    let local2name = e.currentTarget.dataset.local2name;
    let local3name = e.currentTarget.dataset.local3name;
    let type = this.data.type;
    if (type == 0) {
      wx.setStorageSync('addressName', name);
      wx.setStorageSync('addressPhone', phone);
      wx.setStorageSync('addressId', id);
      wx.setStorageSync('addressAddress', local1name+local2name+local3name+adress);
      wx.setStorageSync('addressLocal1', local1);
      wx.setStorageSync('addressLocal2', local2);
      wx.setStorageSync('addressLocal3', local3);
      wx.navigateBack({
        delta: 1
      })
    }else{
      wx.navigateTo({
        url: '/pages/my/addressRedact/addressRedact?id='+id+'&name='+name+'&phone='+phone+'&local1='+local1+'&local2='+local2+'&local3='+local3+'&adress='+adress+'&local1name='+local1name+'&local2name='+local2name+'&local3name='+local3name,
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      list:[]
    })
    this.getAddressList();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (this.data.hasMoreData) {
      // console.log('触底了')
      this.getAddressList()
    }
  }
})